package edu.sctu.jsoup.service;

import edu.sctu.jsoup.entity.CarEntity;
import edu.sctu.jsoup.repo.CarRepo;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Service
public class CarService {

    @Autowired
    private CarRepo carRepo;

    public void run(){
        try {
            Document document = Jsoup.connect("http://club.autohome.com.cn/#pvareaid=103419").get();

            Elements elements = document.select("div.forum-brand-box").first().select("a");
            CarEntity carEntity = new CarEntity();

            for (Element element :elements){
//                String url ="http://club.autohome.com.cn"+element.attr("href");
//                String title = element.text();
                System.out.println(element.text());
//                carEntity.setTitle(title);
//                carEntity.setUrl(url);
//                carEntity.setTime(System.currentTimeMillis());
//                carRepo.save(carEntity);
            }


        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
